1 00:00:00,360 --> 00:00:04,800 Now let's get our equipment storage utils talking to our shop. 2 00:00:04,800 --> 00:00:10,530 So when somebody buys something from the shop on the server side, it's going to be recorded here and 3 00:00:10,530 --> 00:00:13,170 then the players are going to have a record of what they own. 4 00:00:13,170 --> 00:00:14,840 We'll be able to store that off. 5 00:00:14,850 --> 00:00:17,730 Let's go to our Activate Shop script. 6 00:00:17,730 --> 00:00:18,810 I have it open. 7 00:00:18,810 --> 00:00:21,060 That's the server side shop script. 8 00:00:21,060 --> 00:00:25,890 If you can't find it, we can right click and show and explore. 9 00:00:26,930 --> 00:00:28,370 It is in the workspace. 10 00:00:28,370 --> 00:00:32,340 Under shop, under bell, under bell top activate shop script. 11 00:00:32,360 --> 00:00:36,590 This is where we do the money subtraction and we equip the player with the item. 12 00:00:37,100 --> 00:00:37,460 All right. 13 00:00:37,460 --> 00:00:41,240 So I'm going to do a little bit of code cleanup right here. 14 00:00:41,600 --> 00:00:44,630 I'm not going to use the item price coming from the client. 15 00:00:44,630 --> 00:00:46,850 It's just bothering me too much. 16 00:00:46,850 --> 00:00:47,160 Right. 17 00:00:47,180 --> 00:00:51,500 Because people can hack it and you don't want a player taking advantage of your game. 18 00:00:51,840 --> 00:00:52,490 All right. 19 00:00:52,490 --> 00:00:53,480 Right here. 20 00:00:53,480 --> 00:00:55,400 We're going to have to do something about that. 21 00:00:55,400 --> 00:00:57,230 How do we subtract the price? 22 00:00:57,230 --> 00:00:59,600 Well, we do have an a cloned item. 23 00:00:59,600 --> 00:01:01,250 We called it item clone. 24 00:01:01,250 --> 00:01:06,260 We could put a price on the item and use that value. 25 00:01:06,410 --> 00:01:11,150 Then that price is going to come from the item that we purchased. 26 00:01:11,150 --> 00:01:13,850 We can get rid of this if statement. 27 00:01:14,870 --> 00:01:18,410 Let's go ahead and fix our indents. 28 00:01:20,060 --> 00:01:23,220 And we just have to make sure this price is on our items. 29 00:01:23,240 --> 00:01:25,670 Let's go to replicated storage. 30 00:01:26,180 --> 00:01:27,650 Fabulous, Lemon. 31 00:01:28,530 --> 00:01:30,090 Well, that was 2000, right? 32 00:01:30,090 --> 00:01:31,530 So we got an int value. 33 00:01:33,110 --> 00:01:34,100 There we go. 34 00:01:35,040 --> 00:01:39,840 And we'll call that price and then we'll make the value 2000. 35 00:01:41,230 --> 00:01:46,420 Now, the one thing that we should do is we need to be able we should write code to actually grab the 36 00:01:46,420 --> 00:01:47,870 prices on the client side. 37 00:01:47,890 --> 00:01:54,350 Right now, we still have to coordinate the price on the item to the price in the shop. 38 00:01:54,370 --> 00:01:56,740 A little bit of extra level of work. 39 00:01:56,740 --> 00:02:01,720 We've got to do that we could make mistakes on, but that's further down the road if we want to go that 40 00:02:01,720 --> 00:02:02,360 route. 41 00:02:02,380 --> 00:02:06,310 So the simple pistol, we also need a price that's in value. 42 00:02:08,160 --> 00:02:09,800 And we'll call that price. 43 00:02:09,810 --> 00:02:14,400 So everything in your shop is going to need a price based on this new change. 44 00:02:15,390 --> 00:02:18,120 And what was the simple pitch to 1000? 45 00:02:19,380 --> 00:02:21,060 All right, let's test it out. 46 00:02:21,870 --> 00:02:23,460 I hit the play button here. 47 00:02:24,060 --> 00:02:25,530 We'll go to view. 48 00:02:26,390 --> 00:02:28,510 Output a little bit. 49 00:02:28,530 --> 00:02:28,950 Output. 50 00:02:29,000 --> 00:02:30,710 Just look for some red stuff there. 51 00:02:31,640 --> 00:02:35,660 And I have 24,600 points currently. 52 00:02:35,930 --> 00:02:38,180 I'm going to hit the buy button. 53 00:02:38,270 --> 00:02:40,190 There's my simple pistol. 54 00:02:40,220 --> 00:02:41,810 This should cost 1000. 55 00:02:41,840 --> 00:02:44,060 This should go down to 23 600. 56 00:02:44,690 --> 00:02:45,400 Boom. 57 00:02:45,410 --> 00:02:45,950 23. 58 00:02:45,950 --> 00:02:46,690 600. 59 00:02:46,700 --> 00:02:47,780 Nice. 60 00:02:47,780 --> 00:02:54,400 Still not talking to our equipment storage utils yet though, but we're just testing this out. 61 00:02:54,410 --> 00:02:57,260 This should go down 2000 to 20 1 to 600. 62 00:02:57,530 --> 00:02:58,730 Nice. 63 00:02:58,760 --> 00:03:00,860 All right, so we're still going to lose our stuff. 64 00:03:01,100 --> 00:03:02,990 Let's go ahead and start working on that. 65 00:03:04,890 --> 00:03:09,600 I'm in my activate shop script right now, and this is the server side shop script. 66 00:03:09,600 --> 00:03:13,770 When we buy an item, we're going to equip the player and subtract the money. 67 00:03:13,860 --> 00:03:19,620 We need to record the information that happened here in our equip storage utils so we could save to 68 00:03:19,620 --> 00:03:21,930 the database and we don't lose the information. 69 00:03:21,930 --> 00:03:25,080 That is, we don't lose the equipment for our players. 70 00:03:25,350 --> 00:03:32,430 Let's make a variable up near the top local equip utils. 71 00:03:32,430 --> 00:03:34,950 This is going to be pointing to our module script. 72 00:03:34,950 --> 00:03:37,440 We're going to require the module script. 73 00:03:37,440 --> 00:03:43,800 We've got to do game dot server script, service, dot, equip, storage, utils to get a reference 74 00:03:43,800 --> 00:03:44,430 to it. 75 00:03:44,430 --> 00:03:49,500 And then this is going to have all of the information for our storage utils. 76 00:03:50,470 --> 00:03:53,230 Before we call equip storage utils. 77 00:03:53,230 --> 00:03:55,030 We need a helper function now. 78 00:03:55,450 --> 00:04:03,610 I'll do a local function and the helper function will be make info table and we'll pass the item that 79 00:04:03,610 --> 00:04:04,670 we just bought. 80 00:04:04,690 --> 00:04:11,850 So this is going to be the cloned item down here, this item clone and make info table. 81 00:04:11,860 --> 00:04:16,120 I'm going to make a table do local call this item table. 82 00:04:16,570 --> 00:04:22,780 And as an equal sign curly bracket, we're going to need a key value pair. 83 00:04:22,780 --> 00:04:30,130 I'll do name equals item, dot name. 84 00:04:30,130 --> 00:04:34,330 And that way we're going to have at least the item name, which is currently all we're using, but we 85 00:04:34,330 --> 00:04:36,070 want to use those configuration values. 86 00:04:36,070 --> 00:04:43,660 So let's get a variable for config and I have my item. 87 00:04:43,660 --> 00:04:46,930 Find first child. 88 00:04:48,360 --> 00:04:52,950 Configuration folder on at least the simple pistol. 89 00:04:52,950 --> 00:04:55,470 So you look in here, there's a configuration. 90 00:04:55,470 --> 00:04:56,520 Oh, nice. 91 00:04:56,520 --> 00:04:59,850 But the simple lemon doesn't have or the fabulous lemon doesn't have it. 92 00:05:00,060 --> 00:05:02,130 But that's why we're doing a fine first child. 93 00:05:02,130 --> 00:05:06,210 So we'll do an if config just to make sure it exists. 94 00:05:06,300 --> 00:05:11,610 If it does exist, let's loop through all of the configuration values. 95 00:05:11,610 --> 00:05:15,480 Right now we only have cooldown on the pistol, but we may want to add more. 96 00:05:15,480 --> 00:05:17,520 We might want to put ammo reserved ammo. 97 00:05:17,520 --> 00:05:29,430 So for I and V in pairs for the config colon get children, you need to have extra parentheses there 98 00:05:30,120 --> 00:05:40,830 do we will have our item table square bracket V is going to be the thing under the configuration. 99 00:05:40,830 --> 00:05:42,510 I is going to be like one, two, three, four. 100 00:05:42,510 --> 00:05:51,720 So this is going to be a cool down if I do v dot name that's going to actually say cool down equal to 101 00:05:51,720 --> 00:05:53,550 V dot value. 102 00:05:53,550 --> 00:05:57,230 That is that value there, which is a one, right? 103 00:05:57,240 --> 00:06:04,440 So if you have ammo and ammo is equal to six, this right here will be ammo, this will be six. 104 00:06:04,440 --> 00:06:05,850 You get the idea right. 105 00:06:06,330 --> 00:06:14,730 We'll get down to here, will return our item table and then where are we going to use that? 106 00:06:14,730 --> 00:06:20,760 Well, we're going to use that in our shop re on server event where we buy our items. 107 00:06:20,760 --> 00:06:26,220 So we clone the item and then we need to get a table with the item info. 108 00:06:26,430 --> 00:06:29,310 So do local item. 109 00:06:29,340 --> 00:06:30,120 Oh my gosh. 110 00:06:30,120 --> 00:06:40,530 Item table make info table passed in the item clone. 111 00:06:40,530 --> 00:06:40,860 Right. 112 00:06:40,860 --> 00:06:42,380 So we're going to pass that in. 113 00:06:42,390 --> 00:06:43,770 That's going to be right there. 114 00:06:43,770 --> 00:06:46,320 We're going to get an item table with all of our items. 115 00:06:46,320 --> 00:06:47,130 We're going to return it. 116 00:06:47,130 --> 00:06:52,650 It's going to be right here and we're going to be able to use it after we subtract the price from our 117 00:06:52,650 --> 00:06:53,880 points value. 118 00:06:54,360 --> 00:06:56,190 Let's scroll up a little bit. 119 00:06:57,300 --> 00:07:03,360 Let's make a call to our equip utils add item to player's inventory. 120 00:07:03,510 --> 00:07:04,350 There we go. 121 00:07:04,350 --> 00:07:09,000 We're going to pass in the player and then we're going to pass in the item table. 122 00:07:10,280 --> 00:07:15,170 Item table, the one we got from make info table right here. 123 00:07:15,320 --> 00:07:25,310 Now let's go over to our module script, equip storage, utils and add items to player inventory. 124 00:07:25,310 --> 00:07:27,090 Doesn't have anything in it. 125 00:07:27,110 --> 00:07:27,650 That's all right. 126 00:07:27,650 --> 00:07:28,000 That's good. 127 00:07:28,000 --> 00:07:29,060 And change that. 128 00:07:29,060 --> 00:07:35,780 We need to add this table to this main table using the player as the key. 129 00:07:35,780 --> 00:07:41,870 So we have all of the items for all of the players and then when we do saves, we'll be able to update 130 00:07:41,870 --> 00:07:44,180 players as they're playing and they're buying stuff. 131 00:07:44,180 --> 00:07:44,630 Right? 132 00:07:44,630 --> 00:08:00,140 So let's check to see if there is not equipment table player data in this table for that particular 133 00:08:00,140 --> 00:08:00,530 player. 134 00:08:00,530 --> 00:08:00,740 Right. 135 00:08:00,740 --> 00:08:05,780 So if the player doesn't have any equipment, didn't buy any equipment and this is the first thing they're 136 00:08:05,780 --> 00:08:11,540 buying, what we need to do is initialize that table for them. 137 00:08:11,810 --> 00:08:12,320 Right. 138 00:08:12,320 --> 00:08:14,630 Oop, get don't forget your equal sign. 139 00:08:14,630 --> 00:08:14,900 Right. 140 00:08:14,900 --> 00:08:19,730 So we're going to initialize that table so they don't get an error under the if statement. 141 00:08:19,730 --> 00:08:27,500 Let's get a table dot insert and then we have our equipment table for the player. 142 00:08:27,500 --> 00:08:29,900 It might be empty, but it won't be nil. 143 00:08:29,900 --> 00:08:33,320 And then we'll get this table right here. 144 00:08:33,530 --> 00:08:35,540 Item info Table. 145 00:08:35,540 --> 00:08:38,600 It's got our item info that we just sent over. 146 00:08:38,600 --> 00:08:40,160 We're going to paste that there. 147 00:08:40,160 --> 00:08:44,560 And now the equipment table for the player is going to have all the stuff in it. 148 00:08:44,570 --> 00:08:50,330 Let's go ahead and do a print statement for our entire equipment table. 149 00:08:50,420 --> 00:08:54,860 And since we're testing with only one player, it's not going to be a big deal, right? 150 00:08:55,550 --> 00:08:55,820 All right. 151 00:08:55,820 --> 00:08:56,900 Let's try this thing out. 152 00:08:56,900 --> 00:08:58,220 I'm going to hit play. 153 00:08:58,370 --> 00:09:03,170 And then while it's starting up, I'm going to go to my view output. 154 00:09:03,170 --> 00:09:08,990 So we have an output window and then go to these three dots, make sure log mode is off. 155 00:09:08,990 --> 00:09:13,310 That way you can see the entire table rather than just the hexadecimal address. 156 00:09:13,310 --> 00:09:15,560 So logger mode unchecked. 157 00:09:16,070 --> 00:09:20,120 And let's shrink this down a little bit while we're making a purchase. 158 00:09:22,180 --> 00:09:23,200 Come over here. 159 00:09:24,510 --> 00:09:25,110 Bam. 160 00:09:25,140 --> 00:09:26,460 Simple pistol. 161 00:09:27,030 --> 00:09:27,630 Buy it. 162 00:09:28,260 --> 00:09:28,890 Cool. 163 00:09:28,920 --> 00:09:30,150 We can open it up. 164 00:09:30,270 --> 00:09:31,620 I've got to make this bigger again. 165 00:09:33,520 --> 00:09:34,330 Open it up. 166 00:09:34,330 --> 00:09:36,670 This right here is a reference to our player. 167 00:09:36,760 --> 00:09:38,290 We are in the equipment table. 168 00:09:38,290 --> 00:09:39,180 There's the player. 169 00:09:39,190 --> 00:09:40,750 What does the player have? 170 00:09:40,840 --> 00:09:49,780 Are the player has a table here that has cooldown and the name of the instrument or the name of the 171 00:09:49,780 --> 00:09:50,230 equipment. 172 00:09:50,230 --> 00:09:52,510 The item is simple pistol. 173 00:09:52,510 --> 00:09:54,490 What happens if we get the lemon? 174 00:09:55,600 --> 00:09:56,290 Ding. 175 00:09:56,680 --> 00:09:57,450 Fabulous. 176 00:09:57,460 --> 00:09:58,150 Lemon. 177 00:09:58,830 --> 00:09:59,690 Buy it. 178 00:09:59,700 --> 00:10:00,060 All right. 179 00:10:00,060 --> 00:10:01,410 We've got two things. 180 00:10:02,380 --> 00:10:03,220 Scroll down. 181 00:10:03,220 --> 00:10:05,260 Here's the updated equipment table. 182 00:10:06,630 --> 00:10:09,020 And we have our player right here. 183 00:10:09,030 --> 00:10:11,730 Let's open the equipment table for the player. 184 00:10:12,570 --> 00:10:13,320 Look at that. 185 00:10:13,320 --> 00:10:15,900 We got our simple pistol with our cool down in it. 186 00:10:15,900 --> 00:10:17,870 We have our fabulous lemon. 187 00:10:17,880 --> 00:10:19,170 It just has a name. 188 00:10:19,170 --> 00:10:22,020 So we have two items under that player. 189 00:10:22,020 --> 00:10:23,130 That's pretty cool. 190 00:10:23,130 --> 00:10:24,210 We can work with that. 191 00:10:24,210 --> 00:10:26,790 Let's go ahead and start saving that stuff off.